/**
    dirtree.h - Header file for dirtree.c.
    Copyright (C) 2009  Abram Magner

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef DIRTREE_H
  #define DIRTREE_H

  #include <time.h>
  #include "list.h"

  #define DIR_FLAG 0x01
  #define REAL_FLAG 0x02		// 1 if the given node represents a real
                                        // file or directory.

  typedef struct tree_node
  {
    char *name;
    time_t mod_timestamp;		// The latest modification time.
    struct tree_node *parent;
    list *children;
    unsigned char flags;
  } tree_node;

  typedef struct fs_tree
  {
    tree_node *root;
  } fs_tree;

  fs_tree *new_tree (void);
  void free_tree (fs_tree *);

  tree_node *tree_lookup (fs_tree *, char *);
  int tree_insertpath (tree_node *, char *, unsigned char);

  char *tree_getpathname (tree_node *);
  tree_node *new_tree_node (char *, unsigned char, tree_node *);
  tree_node *tree_addchild (tree_node *, char *, unsigned char);
  tree_node *tree_getchild (tree_node *, char *);
  tree_node *tree_getparent (tree_node *);
  char *tree_get_real_path (tree_node *, char *);

  void tree_print (tree_node *);
#endif
